package com.qbw.app.module.vehicle.holder;

import android.content.Context;
import android.view.ViewGroup;

import com.qbw.app.Constant;
import com.qbw.app.R;
import com.qbw.app.databinding.VehicleHolderNotificationItemBinding;
import com.qbw.app.model.Warning;
import com.qbw.app.module.common.holder.CommonHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author QBW
 * @date 2019-10-03
 */
public class VehicleNotificationItemHolder extends CommonHolder<Warning, VehicleHolderNotificationItemBinding> {

    public VehicleNotificationItemHolder(Context context, ViewGroup viewParent) {
        super(context, R.layout.vehicle_holder_notification_item, viewParent);
    }

    @Override
    public void bindData(int position, Warning data) {
        super.bindData(position, data);
        mBinding.setNotification(data);
        mBinding.executePendingBindings();
        mBinding.sc.setOnCheckedChangeListener((b, c) -> {
            List<String> alarmIds = new ArrayList<>();
            alarmIds.add(mData.getAlarmId() + "");
            mGeneralManager.getRequestManager()
                           .getVehicleRequest()
                           .updateWarningConfig(mData.getVehicleCode(),
                                                alarmIds,
                                                c ? Constant.WARNING_NOTIFICATION_OPEN : Constant.WARNING_NOTIFICATION_CLOSED,
                                                null)
                           .execute();
        });
    }
}
